package org.ruanjj.functional;

import java.util.Comparator;
import java.util.function.BiPredicate;
import java.util.function.Supplier;

public class Main {
    public static void main(String[] args) {
        MyFunction m = () -> System.out.println("let me try");
        m.getUser();

        User u = new User("Mary", 12);
        //1.匿名内部类
        Supplier<String> s = new Supplier() {
            @Override
            public String get() {
                return u.getName();
            }
        };

        System.out.println(s.get());

        //2.Lambda
        Supplier<String> s1 = ()-> u.getName();
        System.out.println(s1.get());

        //3.方法引用
        Supplier<String> s2 = u :: getName;
        System.out.println(s2.get());

        //1.匿名内部类
        Comparator<Integer> c = new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return Integer.compare(o1,o2);
            }
        };

        System.out.println(c.compare(2, 10));

        //2.lambda
        Comparator<Integer> c1 = (o1,o2) -> Integer.compare(o1,o2);
        System.out.println(c1.compare(10, 8));

        //3.引用
        Comparator<Integer> c2 = Integer :: compare;
        System.out.println(c2.compare(9, 7));

        BiPredicate<String,String> b = new BiPredicate<String, String>() {
            @Override
            public boolean test(String s, String s2) {
                return s.equals(s2);
            }
        };

        System.out.println(b.test("ab", "cc"));

        BiPredicate<Integer,Integer> b1 = (t1,t2)->t1.equals(t2);
        System.out.println(b1.test(1, 3));

        BiPredicate<Double,Double> b2 = Double :: equals;
        System.out.println(b2.test(2.34, 2.34));
    }
}
